package com.lv.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lv.mapper.TbBrandMapper;
import com.lv.pojo.TbBrand;
import com.lv.pojo.TbBrandExample;
import com.lv.service.BrandService;
import com.lv.util.Page;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class BrandServiceImpl implements BrandService {

    @Resource
    private TbBrandMapper bm;

    @Override
    public Page<TbBrand> brandList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> list = bm.selectByExample(null);
        PageInfo info = new PageInfo(list);
        return new Page(pageNum,pageSize,info.getTotal(),info.getList(),info.getPages());
    }

    //增加

    @Override
    public Integer add(TbBrand b) {
        return bm.insertSelective(b);
    }
    //回显
    @Override
    public TbBrand toupdate(Long id) {
        return bm.selectByPrimaryKey(id);
    }
    //修改

    @Override
    public Integer update(TbBrand b) {
        return bm.updateByPrimaryKeySelective(b);
    }

    @Override
    public Integer delBrands(List<Long> ids) {
        for (long id: ids) {
            bm.deleteByPrimaryKey(id);
        }
        return 1;
    }

    //查询全部

    @Override
    public List<TbBrand> selectAll() {
        return bm.selectByExample(null);
    }
}
